import { PageConfig } from 'next';
import anylogger from 'anylogger';
import '@mmstudio/an000042';
import an48 from '@mmstudio/an000048';
import { tbcurriculum } from '../../../../atoms/db';

const logger = anylogger('pages/api/basicinformation/curriculum/detail.api');

export type IData = ITbcurriculum;

export type Result = {
	data: IData;
};


export type Query = {
	/**
	 * id
	 */
	id: string;
}

/**
 * 课程管理-详情查询
 */
const handler = an48<Result>();

handler.get(async (req, res) => {
	try {
		logger.debug('msg query:', req.query);
		//解析查询条件
		const { id } = req.query as Query;
		//获取数据
		if (!id) {
			res.status(200).json({
				data: {} as IData
			});
			return;
		}
		const data = await tbcurriculum().first('*').where({ curriculum_id: id });
		res.status(200).json({
			data
		});
	} catch (error) {
		logger.error(error);
		logger.trace(error);
		res.status(200).json({
			data: {} as IData
		});
	}
});

export const config = {} as PageConfig;

export default handler;
